#
# Makefile to make the file libclientserver.a, containing
# connection.o and server.o
#

CXX		 = g++
CXXFLAGS	 = -ggdb  -Wall -W -pedantic-errors
CXXFLAGS	+= -Wmissing-braces -Wparentheses
# The following option cannot be used since some of the socket
# macros give warnings on "old-style-cast"
#CXXFLAGS	+= -Wold-style-cast
VPATH = src
SRC	= $(wildcard *.cc)

.PHONY: all clean cleaner



all: libclientserver.a memserver discserver client
	cp memserver bin/memserver
	cp discserver bin/discserver
	cp client bin/client
	mkdir -p bin/newsgroups
	rm memserver
	rm discserver
	rm client


# Create the library; ranlib is for Darwin and maybe other systems.
# Doesn't seem to do any damage on other systems.

libclientserver.a: connection.o server.o
	ar rv libclientserver.a \
	connection.o server.o
	ranlib libclientserver.a
	
clean:
	$(RM) *.o
	$(RM) *.d

cleaner: clean
	$(RM) libclientserver.a
	$(RM) bin/index
	rm -rf bin/newsgroups/*

memserver: memserver.o messagehandler.o database.o libclientserver.a
	$(CXX) -o $@ $^
	
discserver: discserver.o messagehandler.o discobase.o libclientserver.a
	$(CXX) -o $@ $^	

client: client.o libclientserver.a messagehandler.o
	$(CXX) -o $@ $^

%.d: %.cc
	@set -e; rm -f $@; \
	 $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
	 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	 rm -f $@.$$$$

include $(SRC:.cc=.d)
